package com.jbp.service;

import com.jbp.redis.RedisConfigService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.io.FileWriter;
import java.util.LinkedHashMap;

@SpringBootTest
public class CreaeUserTask {
    @Autowired
    private RedisConfigService redisConfigService;

    //保存小号
//    @Test
    public void saveUsers(){
        for (int z = 17; z < 20; z++) {
            String fileName="虎啸小号"+z;
            for (int j = 1; j <= 1000; j++) {
                printUser("-----------第"+j+"组-------------"+"\n", fileName);
                System.out.println("-----------第"+j+"组-------------");
                String key = "user:new:cache";
                String  users = (String)redisConfigService.lget(key);
                while (users==null) {
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    users = (String)redisConfigService.lget(key);
                }
                System.out.print(users);
                printUser(users, fileName);
            }
        }
    }

    static LinkedHashMap<Integer, Double> printUser(String users, String fileName){
        try {
            FileWriter fileWriter = new FileWriter(fileName+".txt", true);
            fileWriter.write(users);
            fileWriter.flush();
            fileWriter.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
